package com.itheima.service.impl;

import com.itheima.mapper.LoginMapper;
import com.itheima.pojo.KsClass;
import com.itheima.pojo.User;
import com.itheima.service.LoginService;
import com.itheima.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class LoginServiceImpl implements LoginService {

    @Autowired
    private LoginMapper loginMapper;

    @Override
    public ResponseResult getClassByMobile(String mobile) {

        Integer role;
        role = loginMapper.findUserRoleIdByMobile(mobile);

        if (role != null){

            if (role == 1) {

                List<KsClass> aClass = loginMapper.findClass(mobile, role);

                return new ResponseResult(0,"操作成功",aClass);

            }else if (role == 2){
                return new ResponseResult(0,"操作成功","学生账号");
            }

        }

        return new ResponseResult(1,"获取失败");

    }

    @Override
    public User findUserByClassIdMobilePassword(Map<String,String> map) {

        return loginMapper.findUserByClassIdMobilePassword(map.get("name"),map.get("password"));
//        Integer.parseInt(map.get("classId")),



    }

}
